package org.example.autofilearchiver.toolclass.ELSE;

import java.util.ArrayList;
import java.util.List;

// 树节点类，代表文件夹或文件  
public class TreeNode {

    String name; // 节点名称（文件夹名或文件名）
    List<TreeNode> children; // 子节点列表  
    boolean isDirectory; // 标识是否为文件夹  
    String path;//存储绝对路径

    TreeNode(String name, boolean isDirectory) {
        this.name = name;
        this.isDirectory = isDirectory;
        this.children = new ArrayList<>();
    }


    public TreeNode(String path, String name, boolean isDirectory) {
        this.path = path;
        this.name = name;
        this.isDirectory = isDirectory;
        this.children = new ArrayList<>();
    }

    // 添加子节点
    public void addChild(TreeNode child) {
        children.add(child);
    }

    // 打印树状结构（递归方法）  
    public void printTree(String indent) {
        System.out.println(indent + (isDirectory ? "+" : "-") + " " + name);
        for (TreeNode child : children) {
            child.printTree(indent + (isDirectory ? "|  " : "   "));
        }
    }
}
